@isTest
private class EngineerHandoverControllerTest {
    static testMethod void testMethod1() {
        	
         Id ldcProfile = [Select Id From Profile Where Name like '%工程师%' limit  1  ].Id;

         User u1 = new User( Alias = 'samLdc1', 
                         Email = 'ldc@test.com.maike',
                         Emailencodingkey = 'UTF-8', 
                         Lastname = '用户1', 
                         Languagelocalekey = 'en_US',
                         Localesidkey = 'en_US', 
                         Profileid = ldcProfile, 
                         Country = 'United States',
                         IsActive = true,
                         CompanyName= 'Y-MKSY',
                         SubCompany__c='四川省迈克实业有限公司',
                         UserDepartment__c='客户服务中心(工程部)',
                         Timezonesidkey = 'America/Los_Angeles', 
                         EmployeeNumber = '123451',
                         Province__c = '四川省',
                         Username = 'Matldc1@test.com.maike',
                         FederationIdentifier ='123451', 
                         ManagerId=UserInfo.getUserId(), 
                         ResponseCode__c = 'TTTT' );
         insert u1; 

        Account acc=new Account();
    	acc.Name='Test1229J';
    	insert acc;

        UserInformation__c uinfo1= new UserInformation__c();
        uinfo1.SubCompany__c = '四川省迈克实业有限公司';
        uinfo1.OrderProcessingAssistant__c = UserInfo.getUserId();
        uinfo1.SalesAssistant__c = UserInfo.getUserId();
        uinfo1.EngineeringAssistant__c = UserInfo.getUserId();
        insert uinfo1; 

    	Product__c p1 = TestUtils.createProduct();
        p1.Brand__c = '迈克';
        p1.Category3__c = '配件';
        p1.Category0__c = '配件';
         p1.Company__c = '四川省迈克实业有限公司';
        p1.RecordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('NCProduct', 'Product__c');
        p1.NCCode__c = '1101110000';
        insert p1;


        PartsLendingApplication__c pla = new PartsLendingApplication__c();
        pla.IsSycToNc__c = true;
        pla.InventoryOrganization__c = 'MKSY';
        pla.InvoicingCustomers__c =acc.Id  ;
        insert pla;

        PartsLendingDetails__c pld = new PartsLendingDetails__c();
        pld.Product__c = p1.Id;
        pld.No__c =5;
        pld.A_InvoiceNo__c = 1;
        pld.A_WarrantyNo__c =1;
        pld.B_No__c = 5;

        pld.PartsLendingApplication__c = pla.Id;
        insert pld;




        EngineerHandover__c  eh = new EngineerHandover__c();
        insert eh ;


         PageReference page2 = new PageReference('/apex/EngineerHandover?id='+eh.Id);
            System.Test.setCurrentPage(page2);

        EngineerHandoverController pra = new EngineerHandoverController();
        pra.init();


        Map<String,Object> saveMap =new Map<String,Object>();


        saveMap.put('commit', 'false');
        Map<String,String> dataMap = new Map<String,String>();
        dataMap.put('userId', u1.Id );
        dataMap.put('num', '5' );
        dataMap.put('productId', p1.Id  );
        dataMap.put('detailId', pld.Id);
        List<Object> d = new List<Object>();
        d.add(dataMap);
        saveMap.put('data',d );

        System.debug('EngineerHandoverControllerTest==>'+saveMap);

        pra.saveJson = EncodingUtil.urlEncode(JSON.serialize(saveMap), 'UTF-8');
        pra.save();


        pra.init();

        //EngineerHandoverHandler test 
        EngineerHandoverHandler.toComfirm(eh.Id);
        List<HandoverDetails__c> hL = [select Id from  HandoverDetails__c where MasterTable__c =:eh.Id];
        System.debug('EngineerHandoverControllerTest==>'+hL);
         for ( HandoverDetails__c h  :hL ) {
        	h.ConfirmHandover__c = true;
        }	
        update hL;


        eh.Status__c = '已批准';
        update eh ;
		




    }
}